package cm.project;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test8 {
    public static void main(String[] args) {
        File file = new File("file/img1");
        File[] files = file.listFiles();
        String appendPath = null;


        for (File ele : files) {
            if (ele.isFile() && ele.exists()) {
                appendPath = ele.getPath().split("img1")[1];
//                System.out.println(appendPath);

                try (
                        FileInputStream fis = new FileInputStream(ele);
                        FileOutputStream fos = new FileOutputStream("file\\img2" + appendPath);
                ) {
                    byte[] buf2 = new byte[8192];
                    int len = -1;
                    while ((len = fis.read(buf2)) != -1) {
                        fos.write(buf2, 0 , len);
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
